// 示例：此文件为 商品相关的接口
import axios from "@/utils/axios";

// 获取每个分类的商品信息
function getClassifyGoods() {
    return axios({
        method: "get",
        url: "/api/classify/classifyGoods",
        params: {
            project_id: 217,
        },
    });
}

function login(phone, password) {
    return axios({
        method: "post",
        url: "/api/login",
        data: {
            phone: phone,
            password: password,
        },
    });
}
// 商品详情页轮播图
function getDetails() {
    return axios({
        method: "get",
        url: "/api/carousel",
        params: {
            project_id: 217,
            site_id: 274,
        },
        // headers: { "x-token": localStorage.getItem("token") },
    });
}
// 商品详情介绍图
function getDetailsIntroduce() {
    return axios({
        method: "get",
        url: "/api/carousel",
        params: {
            project_id: 217,
            site_id: 277,
        },
        // headers: { "x-token": localStorage.getItem("token") },
    });
}
// 获取商品列表 getGoodsList返回promise对象
function getGoodsList() {
    // axios promise对象
    return axios({
        method: "get",
        url: "/api/goods",
        params: {
            project_id: 217,
        },
        // headers: { "x-token": localStorage.getItem("token") },
    });
}
// 搜索商品
function searchProduct(name) {
    // axios promise对象
    return axios({
        method: "get",
        url: "/api/goods",
        params: {
            project_id: 217,
            name: name,
        },
        // headers: { "x-token": localStorage.getItem("token") },
    });
}
// 添加购物车
function addCart(goods_id, num) {
    return axios({
        method: "post",
        url: "/api/shoppingCart",
        data: {
            project_id: 217,
            goods_id: goods_id,
            num: num,
        },
        headers: { "x-token": localStorage.getItem("token") },
    });
}
// 获取购物车数据
function getCartData() {
    return axios({
        method: "get",
        url: "/api/shoppingCart",
        params: {
            project_id: 217,
        },
        headers: { "x-token": localStorage.getItem("token") },
    });
}
// 更新购物车数据
function upDateCart(id, num) {
    return axios({
        method: "put",
        url: `/api/shoppingCart/${id}`,
        data: {
            project_id: 217,
            num: num,
        },
        headers: { "x-token": localStorage.getItem("token") },
    });
}
// 删除购物车一条信息
function deleteCart(id) {
    return axios({
        method: "delete",
        url: `/api/shoppingCart/${id}`,
        data: {
            project_id: 217,
        },
        headers: { "x-token": localStorage.getItem("token") },
    });
}

//首页顶部轮播图
function getCarousel() {
    return axios({
        method: "get",
        url: "api/carousel",
        params: { project_id: 217 },
    });
}
export {
    login,
    getDetails,
    getDetailsIntroduce,
    getGoodsList,
    searchProduct,
    addCart,
    getCartData,
    upDateCart,
    deleteCart,
    getCarousel,
    getClassifyGoods,
};
